from page.index_page import IndexPage, get_driver, By, time
from page.login_page import LoginPage
import unittest

class BrowseProductsTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        driver = get_driver()
        cls.indexpage = IndexPage(driver)


    def test01_browseproducts(self):
        # 登录
        self.indexpage.get(LoginPage.login_url)
        # 定位首页
        self.indexpage.into_index_page()
        # 滑动窗口到底部
        self.indexpage.scroll_to_tail()
        time.sleep(1)
        # 获取目标商品名字
        expect_product_name = self.indexpage.product_name((By.XPATH,'/html/body/div[6]/div/div/div[4]/div[2]/div/a[2]/div[3]'))
        # 点击目标商品图标
        self.indexpage.click((By.XPATH,'/html/body/div[6]/div/div/div[6]/div[2]/div/a[2]/div[1]/img'))
        time.sleep(1)
        # 获取页面商品名
        actual_product_name = self.indexpage.product_name((By.XPATH,'//*[@id="ECS_FORMBUY"]/div'))

        # 断言
        self.assertEqual(expect_product_name,actual_product_name)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.indexpage.page_quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)